package com.zsrt.devbase.common.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;

import org.apache.log4j.Logger;

public class TestPostP
{
	
	private static Logger logger = Logger.getLogger(TestPostP.class);
	
	public static void testPost(String phoneNum,String code) throws IOException 
	{
		URL url = new URL("http://www.lanz.net.cn/LANZGateway/DirectSendSMSs.asp");
		//发短信工具类除了注册还有修改手机等功能需要用到，所以笼统成为验证码
		String urlString = "UserID=754099&Account=13027517559&Password=6481E269BF3FBFE52D91800DCEABEFC1339D8640&Content=您的验证码为"+code+"，该验证码10分钟内有效。如非本人操作请忽略此短信！【浪驰软件】&Phones="+phoneNum+"&ReturnXJ=1";
		logger.info(urlString);
		HttpURLConnection connection = (HttpURLConnection)url.openConnection();
                connection.setRequestMethod("POST");
		connection.setDoOutput(true);
                connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");              
		OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "GB2312");

          
		urlString = urlString.replace("%","％");
		urlString = urlString.replace("+","＋");
		urlString = urlString.replace(" ","+");


		out.write(urlString);
		out.flush();
		out.close();
		
		String sCurrentLine;
		String sTotalString;
		sCurrentLine = "";
		sTotalString = "";
		InputStream l_urlStream;
		l_urlStream = connection.getInputStream();

		BufferedReader l_reader = new BufferedReader(new InputStreamReader(l_urlStream));
		while ((sCurrentLine = l_reader.readLine()) != null) 
		{
			sTotalString += sCurrentLine + "\r\n";
		}
		System.out.println(sTotalString);
	}
}